package com.gewu.pm.ui.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.gewu.pm.R;
import com.gewu.pm.app.AppAdapter;
import com.gewu.pm.bean.CommentBean;

/**
 * 评论列表适配器
 */
public class CommentAdapter extends AppAdapter<CommentBean> {

    public CommentAdapter(Context context) {
        super(context);
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ItemViewHolder();
    }

    private final class ItemViewHolder extends AppAdapter<?>.ViewHolder {

        private final ImageView mAvatarView;
        private final TextView mHeaderView;
        private final TextView mContentView;
        private final TextView mTimeView;

        private ItemViewHolder() {
            super(R.layout.comment_item);
            mAvatarView = findViewById(R.id.iv_avatar);
            mHeaderView = findViewById(R.id.tv_comment_header);
            mContentView = findViewById(R.id.tv_comment_content);
            mTimeView = findViewById(R.id.tv_comment_time);
        }

        @Override
        public void onBindView(int position) {
            CommentBean item = getItem(position);
            
            // 显示姓名和回复信息
            if (!TextUtils.isEmpty(item.getReplyTo())) {
                mHeaderView.setText(item.getName() + " 回复了" + item.getReplyTo());
            } else {
                mHeaderView.setText(item.getName());
            }
            
            // 显示评论内容
            mContentView.setText(item.getContent());
            
            // 显示时间
            mTimeView.setText("2025-06-18 10:00");
        }
    }
}

